package com.filter.inter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;


/**
 * 拦截器
 *
 * @author wdg
 *
 */
public class AbsHandlerInterceptor implements HandlerInterceptor {

	private Logger logger = LoggerFactory.getLogger(AbsHandlerInterceptor.class);

	long start = System.currentTimeMillis();

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler) throws Exception {
		String secretKey = request.getHeader("from");
		if(StringUtils.isEmpty(secretKey)||!secretKey.equals("gateway")){
			response.setContentType("application/json; charset=utf-8");
			PrintWriter writer = response.getWriter();
			writer.write("非法访问");
			return false;
		}
		return true;

	}

}